home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Freeware / Miro 1.0 / Miro_Installer.exe / Miro_Downloader.exe / search.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2007-11-12  |  2.2 KB  |  86 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  3.  
  4. import item
  5. import re
  6. quotekiller = re.compile('(?<!\\\\)"')
  7. slashkiller = re.compile('\\\\.')
  8. searchObjects = { }
  9.  
  10. def match(searchString, comparisons):
  11.     if not searchObjects.has_key(searchString):
  12.         searchObjects[searchString] = BooleanSearch(searchString)
  13.     
  14.     return searchObjects[searchString].match(comparisons)
  15.  
  16.  
  17. class BooleanSearch:
  18.     
  19.     def __init__(self, string):
  20.         self.string = string
  21.         self.parse_string()
  22.  
  23.     
  24.     def parse_string(self):
  25.         inquote = False
  26.         i = 0
  27.         while i < len(self.string) and self.string[i] == ' ':
  28.             i += 1
  29.         laststart = i
  30.         self.rules = []
  31.         while i < len(self.string):
  32.             i = laststart
  33.             while i < len(self.string):
  34.                 if self.string[i] == '"':
  35.                     inquote = not inquote
  36.                 
  37.                 if not inquote and self.string[i] == ' ':
  38.                     break
  39.                 
  40.                 if self.string[i] == '\\':
  41.                     i += 1
  42.                 
  43.                 i += 1
  44.             if inquote:
  45.                 self.rules.append(self.process(self.string[laststart:]))
  46.             else:
  47.                 self.rules.append(self.process(self.string[laststart:i]))
  48.             while i < len(self.string) and self.string[i] == ' ':
  49.                 i += 1
  50.             laststart = i
  51.  
  52.     
  53.     def process(self, substring):
  54.         positive = True
  55.         if substring[0] == '-':
  56.             substring = substring[1:]
  57.             positive = False
  58.         
  59.         substring = quotekiller.sub('', substring)
  60.         substring = slashkiller.sub((lambda x: x.group(0)[1]), substring)
  61.         return [
  62.             positive,
  63.             substring]
  64.  
  65.     
  66.     def match(self, comparisons):
  67.         for rule in self.rules:
  68.             matched = False
  69.             for comparison in comparisons:
  70.                 if rule[1] in comparison:
  71.                     matched = True
  72.                     break
  73.                     continue
  74.             
  75.             if rule[0] != matched:
  76.                 return False
  77.                 continue
  78.         
  79.         return True
  80.  
  81.     
  82.     def as_string(self):
  83.         return self.string
  84.  
  85.  
  86.